package com.wj.controller;

import com.wj.service.communication.AuthorityFeignClient;
import com.wj.service.communication.UseRestTemplateService;
import com.wj.service.communication.UseRibbonService;
import com.wj.vo.JwtToken;
import com.wj.vo.UsernameAndPassword;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微服务通信
 */
@RestController
@RequestMapping("/communication")
public class CommunicationController {

    private final UseRestTemplateService restTemplateService;

    private final UseRibbonService ribbonService;

    private final AuthorityFeignClient feignClient;

    public CommunicationController(UseRestTemplateService restTemplateService, UseRibbonService ribbonService, AuthorityFeignClient feignClient) {
        this.restTemplateService = restTemplateService;
        this.ribbonService = ribbonService;
        this.feignClient = feignClient;
    }

    @PostMapping("/rest-template")
    public JwtToken getTokenFromAuthorityService(@RequestBody UsernameAndPassword usernameAndPassword){
        return restTemplateService.getTokenFromAuthorityService(usernameAndPassword);
    }

    @PostMapping("/rest-template-load-balance")
    public JwtToken getTokenFromAuthorityServiceWithBalance(@RequestBody UsernameAndPassword usernameAndPassword){
        return restTemplateService.getTokenFromAuthorityServiceWithBalance(usernameAndPassword);
    }

    @PostMapping("/thinking-in-ribbon")
    public JwtToken getTokenFromAuthorityServiceByRibbon(@RequestBody UsernameAndPassword usernameAndPassword){
        return ribbonService.getTokenFromAuthorityServiceByRibbon(usernameAndPassword);
    }

    @PostMapping("/token-by-feign ")
    public JwtToken getTokenFromAuthorityServiceByOpenFeign(@RequestBody UsernameAndPassword usernameAndPassword){
        return feignClient.getTokenByFeign(usernameAndPassword);
    }
}
